#ifndef DATA_GENERATE_H
#define DATA_GENERATE_H


#include <QPainter>
#include <QVector>
#include <QPointF>
#include <QDateTime>

#include <QLinearGradient>
#include <cmath>
#include <algorithm>
#include <random>

// K线数据结构
struct KLineData {
    QDateTime date;
    double open;
    double high;
    double low;
    double close;
    double volume;
};

// 生成随机K线数据
inline QVector<KLineData> generateKLineData(int count) {
    QVector<KLineData> data;
    double price = 100.0;
    QDateTime startDate = QDateTime::currentDateTime().addDays(-count);

    std::random_device rd;
    std::mt19937 gen(rd());
    std::normal_distribution<> d(0.0, 1.5);

    for (int i = 0; i < count; ++i) {
        KLineData item;
        item.date = startDate.addDays(i);

        double change = d(gen);
        item.open = price;
        price += change;

        // 确保价格不会为负
        if (price < 1.0) price = 1.0;

        // 模拟价格波动
        double range = std::abs(change) * 2.5;
        item.high = price + std::abs(d(gen)) * range;
        item.low = price - std::abs(d(gen)) * range;

        // 确保高低价合理
        if (item.low > item.open) item.low = item.open - 0.1;
        if (item.low > item.close) item.low = item.close - 0.1;
        if (item.high < item.open) item.high = item.open + 0.1;
        if (item.high < item.close) item.high = item.close + 0.1;

        item.close = price;
        item.volume = 1000000 + std::abs(d(gen)) * 500000;

        data.append(item);
    }
    return data;
}



#endif // DATA_GENERATE_H
